﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NativeCode.Core.Data;

namespace NativeCode.Core.Extensions
{
	public static class EnumExtensions
	{
		public static Dictionary<string, string> ToDictionary<T>(this T enumeration)
			where T : struct
		{
			string[] names = Enum.GetNames(typeof (T));
			return names.ToDictionary(name => name, name => name.ToDisplayText());
		}

		public static string ToSymbol(this QueryFilterOperator filterOperator)
		{
			switch (filterOperator)
			{
				case QueryFilterOperator.Between:
					return "between";
				case QueryFilterOperator.Contains:
					return "contains";
				case QueryFilterOperator.Equals:
					return "=";
				case QueryFilterOperator.GreaterThan:
					return ">";
				case QueryFilterOperator.GreaterThanOrEqualTo:
					return ">=";
				case QueryFilterOperator.LessThan:
					return "<";
				case QueryFilterOperator.LessThanOrEqualTo:
					return "<=";
				case QueryFilterOperator.NotEquals:
					return "!=";
			}

			return string.Empty;
		}

		public static string ToSymbol(this QueryFilterOperator filterOperator, bool htmlEncode)
		{
			return htmlEncode ? HttpUtility.HtmlEncode(filterOperator.ToSymbol()) : filterOperator.ToSymbol();
		}
	}
}